(function(){var t=BX.namespace("BX.UI.TileList");if(t.Manager){return}var e=[];function i(t){this.id=t.id;this.name=t.name;this.bgColor=t.bgColor;this.color=t.color;this.selected=t.selected;this.node=t.node;this.data=t.data;this.nameNode=o.getNode("tile/item/name",this.node);this.iconNode=o.getNode("tile/item/icon",this.node);this.iconColorNode=o.getNode("tile/item/icon/color",this.node);if(this.name){this.nameNode.textContent=this.name}if(t.iconClass){BX.addClass(this.iconNode,t.iconClass)}this.changeSelection(this.selected)}i.prototype={classSelected:"ui-tile-list-item-selected",changeSelection:function(t){o.changeClass(this.node,this.classSelected,t);this.nameNode.style.color=t&&this.color?this.color:"";this.node.style.background=t?this.bgColor?this.bgColor:getComputedStyle(this.iconColorNode).backgroundColor:"";this.selected=t},onClick:function(){}};function n(t){this.init(t)}n.prototype.events={tileClick:"tile-click",tileRemove:"tile-remove",tileEdit:"tile-edit",tileAdd:"tile-add",buttonAdd:"add"};n.getById=function(t){var i=e.filter(function(e){return e.id===t});return i.length>0?i[0]:null};n.getList=function(){return e};n.prototype.init=function(t){this.list=[];this.context=BX(t.containerId);if(!this.context){return}this.id=t.id;this.tileContainer=o.getNode("tile/items",this.context);this.tileTemplate=o.getNode("tile/template",this.context);this.buttonAdd=o.getNode("tile/add",this.context);o.getNodes("tile/item",this.context).forEach(this.initNode.bind(this,t.tileOptionsList||[]));e.push(this);this.initEventHandlers()};n.prototype.initEventHandlers=function(){if(this.buttonAdd){BX.bind(this.buttonAdd,"click",this.onButtonAdd.bind(this))}};n.prototype.initNode=function(t,e){if(!e){return null}var i=e.getAttribute("data-id");var n=t.filter(function(t){return t.id.toString()===i},this);if(n.length===0){return}var o=n[0];o.node=e;this.addTile(o)};n.prototype.onRemove=function(t,e){e.preventDefault();e.stopPropagation();this.removeTile(t);return false};n.prototype.onTileClick=function(t,e){e.preventDefault();e.stopPropagation();this.fire(this.events.tileClick,[t])};n.prototype.removeTiles=function(){var t=this.list;t.forEach(this.removeTile.bind(this))};n.prototype.removeTile=function(t){this.list=BX.util.deleteFromArray(this.list,this.list.indexOf(t));BX.remove(t.node);this.fire(this.events.tileRemove,[t])};n.prototype.getTile=function(t){var e=this.list.filter(function(e){return e.id===t});return e.length>0?e[0]:null};n.prototype.getTiles=function(){return this.list};n.prototype.addTile=function(e){if(!e.node){e.node=o.getTemplatedNode(this.tileTemplate,{})}var i=new t.Tile(e);if(!i){return null}if(!this.tileContainer.contains(i.node)){this.tileContainer.appendChild(i.node)}BX.bind(i.node,"click",this.onTileClick.bind(this,i));this.list.push(i);this.fire(this.events.tileAdd,[i]);return i};n.prototype.fire=function(t,e){BX.onCustomEvent(this,t,e)};n.prototype.onButtonAdd=function(t){t.preventDefault();t.stopPropagation();this.fire(this.events.buttonAdd,[])};var o={getObjectByKey:function(t,e,i){var n=t.filter(function(t){return t.hasOwnProperty(e)&&t[e]===i});return n.length>0?n[0]:null},getNode:function(t,e){var i=this.getNodes(t,e);return i.length>0?i[0]:null},getNodes:function(t,e){if(!e){return[]}return BX.convert.nodeListToArray(e.querySelectorAll('[data-role="'+t+'"]'))},changeClass:function(t,e,i){if(!t){return}if(i){BX.addClass(t,e)}else{BX.removeClass(t,e)}},changeDisplay:function(t,e){if(!t){return}t.style.display=e?"":"none"},replace:function(t,e,i){e=e||{};i=i||false;if(!t){return""}for(var n in e){if(!e.hasOwnProperty(n)){continue}var o=e[n];o=o||"";if(!i&&o){o=BX.util.htmlspecialchars(o)}t=t.replace(new RegExp("%"+n+"%","g"),o)}return t},getTemplatedNode:function(t,e,i){if(!t){return null}var n=o.replace(t.innerHTML,e,i);var r=document.createElement("div");r.innerHTML=n;return r.children[0]}};t.Manager=n;t.Tile=i})();
//# sourceMappingURL=script.map.js